<?php

namespace App\Http\Resources;

use App\Helpers\BaseResource;

class UserBuyOrder extends BaseResource
{
    public function toArray($request)
    {
        return $this->filterFields([
            'order_sn' => $this->order_sn,
            'pay_time' => (string)$this->pay_time,
            'order_money' => $this->order_money,
            'pay_money' => $this->pay_money,
            'user' => $this->when($this->ckFields('user'), function () {
                return User::make($this->user)->show(['name', 'avatar']);
            }),
            'liveroom' => $this->when($this->ckFields('liveroom'), function () {
                return Liveroom::make($this->liveroom)->show(['id', 'title']);
            }),
            'liveroom_log' => $this->when('liveroom_log', function () {
                return MoneyLog::make($this->liveroom_log)->show(['type', 'desc']);
            }),
            'liveroom_money' => $this->liveroom_money,
            'item_type' => $this->item_type,
            'item' => $this->when($this->ckFields('item'), function () {
                switch ($this->item_type) {
                    case \App\Models\Doc::class:
                        $docRes =  Doc::make($this->item);
                        $docRes = $this->get_relate_data('doc',$docRes);
                        return $docRes;
                        break;
                }
            }),
            'tg_money' => $this->tg_money
        ]);
    }
}
